package com.sugar.psych.assessment.module.business.dal.mysql.feedback;

import java.util.*;

import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sugar.psych.assessment.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.psych.assessment.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.sugar.psych.assessment.module.business.dal.dataobject.feedback.FeedbackDO;
import com.sugar.psych.assessment.module.business.dal.dataobject.user.UserDO;
import org.apache.ibatis.annotations.Mapper;
import com.sugar.psych.assessment.module.business.controller.admin.feedback.vo.*;

/**
 * 意见反馈 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface FeedbackMapper extends BaseMapperX<FeedbackDO> {

    default PageResult<FeedbackRespVO> selectPage(FeedbackPageReqVO reqVO) {
        return selectJoinPage(reqVO, FeedbackRespVO.class, new MPJLambdaWrapperX<FeedbackDO>()
                .selectAll(FeedbackDO.class)
                .selectAs(UserDO::getNickname, FeedbackRespVO::getNickname)
                .selectAs(UserDO::getMobile, FeedbackRespVO::getMobile)
                .leftJoin(UserDO.class, UserDO::getId, FeedbackDO::getUserId)
                .eqIfPresent(UserDO::getMobile, reqVO.getMobile())
                .eqIfPresent(FeedbackDO::getUserId, reqVO.getUserId())
                .eqIfPresent(FeedbackDO::getContent, reqVO.getContent())
                .eqIfPresent(FeedbackDO::getAttch, reqVO.getAttch())
                .betweenIfPresent(FeedbackDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(FeedbackDO::getId));
    }

}